package com.beamfield.controller.manage.process;

import com.alibaba.fastjson.JSON;
import com.beamfield.common.ApiResult;
import com.beamfield.common.CommonUtils;
import com.beamfield.controller.common.BaseController;
import com.beamfield.enums.HttpResultEnum;
import com.beamfield.enums.MessageEnum;
import com.beamfield.enums.ProcessEnum;
import com.beamfield.model.*;
import com.beamfield.modelVo.ProcNoticeWithDetailVo;
import com.beamfield.service.manage.process.NoticeService;
import com.beamfield.service.manage.sys.MessageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 通知单
 */
@Controller
@RequestMapping("/cms/process/notice")
public class NoticeController extends BaseController {

    @Autowired
    private NoticeService noticeService;
    @Autowired
    private MessageService messageService;

    @RequestMapping(value = "/notice_detail", method = RequestMethod.GET)
    public ModelAndView notice_detail() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/tjz_notice", method = RequestMethod.GET)
    public ModelAndView tjz_notice() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/tjz_notice_detail", method = RequestMethod.GET)
    public ModelAndView tjz_notice_detail() {

        return new ModelAndView();
    }

    @RequestMapping(value = "/cm_notice", method = RequestMethod.GET)
    public ModelAndView cm_notice() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/cm_notice_detail", method = RequestMethod.GET)
    public ModelAndView cm_notice_detail() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/yzl_notice", method = RequestMethod.GET)
    public ModelAndView yzl_notice() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/yzl_notice_detail", method = RequestMethod.GET)
    public ModelAndView yzl_notice_detail() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/czl_notice", method = RequestMethod.GET)
    public ModelAndView czl_notice() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/czl_notice_detail", method = RequestMethod.GET)
    public ModelAndView czl_notice_detail() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/zzl_notice", method = RequestMethod.GET)
    public ModelAndView zzl_notice() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/zzl_notice_detail", method = RequestMethod.GET)
    public ModelAndView zzl_notice_detail() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/ycl_notice", method = RequestMethod.GET)
    public ModelAndView ycl_notice() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/ycl_notice_detail", method = RequestMethod.GET)
    public ModelAndView ycl_notice_detail() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/dl_notice", method = RequestMethod.GET)
    public ModelAndView dl_notice() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/dl_notice_detail", method = RequestMethod.GET)
    public ModelAndView dl_notice_detail() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/qszj_notice", method = RequestMethod.GET)
    public ModelAndView qszj_notice() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/qszj_notice_detail", method = RequestMethod.GET)
    public ModelAndView qszj_notice_detail() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/fm_notice", method = RequestMethod.GET)
    public ModelAndView fm_notice() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/fm_notice_detail", method = RequestMethod.GET)
    public ModelAndView fm_notice_detail() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/jl_notice", method = RequestMethod.GET)
    public ModelAndView jl_notice() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/jl_notice_detail", method = RequestMethod.GET)
    public ModelAndView jl_notice_detail() {
        return new ModelAndView();
    }

    /**
     * 查询浇筑通知单详细
     * @param id
     * @param req
     * @return
     */
    @RequestMapping(value = "/getTJZDetailInfo", method = RequestMethod.GET)
    @ResponseBody
    public ApiResult getTJZDetailInfo(long id, HttpServletRequest req) {
        ApiResult apiResult = new ApiResult();
        Long beamId = super.getBeamId(req);
        TjzNotice tjzNoticeDetail = noticeService.getTjzNoticeDetail(id,beamId);
        Map<String, Object> map = new HashMap<>();
        map.put("TjzNoticeDetail", tjzNoticeDetail);
        apiResult.setResult(map);
        return apiResult;
    }
    /**
     *添加/更新浇筑通知单
     * @param tjzNoticeJson
     * @param request
     * @return
     */
    @RequestMapping(value = "/updateTJZDetailInfo")
    @ResponseBody
    public ApiResult updateTJZDetailInfo(String tjzNoticeJson, HttpServletRequest request) {
        if (StringUtils.isEmpty(tjzNoticeJson)) {
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        int result = 0;
        try {
            TjzNotice tjzNotice = JSON.parseObject(tjzNoticeJson, TjzNotice.class);
            if(!noticeService.decideCanAdd(tjzNotice.getNotice_id(), ProcessEnum.HNT.getType())){
                return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), "未到当前通知单进度");
            }
            Long beamId = super.getBeamId(request);
            Long userId = super.getUserId(request);
            tjzNotice.setBeam_id(beamId);
            if (tjzNotice.getId() == null) {
                tjzNotice.setOperator(userId);
                tjzNotice.setAddtime(new Date());
                result = noticeService.addTjzNotice(tjzNotice);
                ProcNoticeWithDetailVo beamNoByNoticeId = noticeService.getBeamNoByNoticeId(tjzNotice.getNotice_id());
                Message message = new Message();
                message.setType(MessageEnum.PROC_Beam_TJZ.getType());
                message.setBeam_id(beamId);
                message.setTitle("砼浇筑通知单完成新建提醒");
                message.setContent("施工部位：" + beamNoByNoticeId.getBeam_no() + "的砼浇筑通知单完成新建");
                message.setOperator(userId);
                message.setCode("");
                message.setDetail_url("./process/notice/tjz_notice_detail?notice_id="+beamNoByNoticeId.getNotice_id()+"&step="+(beamNoByNoticeId.getLaststep()+1)
                        +"&cStep="+beamNoByNoticeId.getLaststep()+"&type=1"
                );
                messageService.generateMessageByName(message,tjzNotice.getRecipient());

            } else {
                tjzNotice.setBeam_id(beamId);
                tjzNotice.setUpdatetime(new Date());
                tjzNotice.setUpdater(userId);
                result = noticeService.updateTjzNotice(tjzNotice);

            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 1) {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        } else {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }
    /**
     * 添加/更新拆模通知单
     * @param id
     * @param notice_id
     * @param section
     * @param strength
     * @param time
     * @param writer
     * @param recipient
     * @param company
     * @param reportid
     * @param req
     * @return
     */
    @RequestMapping(value = "/updateCMDetailInfo")
    @ResponseBody
    public ApiResult updateCMDetailInfo(String id, String notice_id, String section, String strength, String time,
                                        String writer, String recipient, String company, String reportid
            , HttpServletRequest req) {
        long beamId = super.getBeamId(req);
        Long userId = super.getUserId(req);
        Date time2 = null;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        try {
            time2 = formatter.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if(!noticeService.decideCanAdd(CommonUtils.parseLong(notice_id, 0L), ProcessEnum.CMSG.getType())){
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), "未到当前通知单进度");
        }
        CmNotice cmNotice = new CmNotice();
        if (StringUtils.isNotBlank(id)) {
            cmNotice.setId(Long.parseLong(id));
        }
        cmNotice.setNotice_id(Long.parseLong(notice_id));
        cmNotice.setSection(section);
        cmNotice.setStrength(strength);
        cmNotice.setTime(time2);
        cmNotice.setWriter(writer);
        cmNotice.setReportid(reportid);
        cmNotice.setRecipient(recipient);
        cmNotice.setCompany(company);
        cmNotice.setBeam_id(beamId);
        ApiResult apiResult = new ApiResult();
        if (StringUtils.isNotBlank(id)) {
            cmNotice.setUpdater(userId);
            cmNotice.setUpdatetime(new Date());
            noticeService.updateCmNotice(cmNotice);


        } else {
            cmNotice.setOperator(userId);
            cmNotice.setAddtime(new Date());
            noticeService.addCmNotice(cmNotice);
            ProcNoticeWithDetailVo beamNoByNoticeId = noticeService.getBeamNoByNoticeId(cmNotice.getNotice_id());
            Message message = new Message();
            message.setType(MessageEnum.PROC_Beam_CM.getType());
            message.setBeam_id(beamId);
            message.setTitle("拆模通知单完成新建提醒");
            message.setContent("施工部位：" + beamNoByNoticeId.getBeam_no() + "的拆模通知单完成新建");
            message.setOperator(userId);
            message.setCode("");
            message.setDetail_url("./process/notice/cm_notice_detail?notice_id="+beamNoByNoticeId.getNotice_id()+"&step="+(beamNoByNoticeId.getLaststep()+1)
                    +"&cStep="+beamNoByNoticeId.getLaststep()+"&type=1"
            );
            messageService.generateMessageByName(message,cmNotice.getRecipient());
        }
        return apiResult;
    }



    /**
     *  查询拆模通知单
     * @param id
     * @return
     */
    @RequestMapping(value = "/getCMDetailInfo")
    @ResponseBody
    public ApiResult getCMDetailInfo(long id,HttpServletRequest req) {
        ApiResult apiResult = new ApiResult();
        Long beamId = super.getBeamId(req);
        CmNotice cmNoticeDetail = noticeService.getCmNoticeDetail(id,beamId);
        Map<String, Object> map = new HashMap<>();
        map.put("CmNoticeDetail", cmNoticeDetail);
        apiResult.setResult(map);
        return apiResult;
    }


    /**
     *更新/添加預張拉通知單
     * @param id
     * @param notice_id
     * @param section
     * @param strength
     * @param time
     * @param writer
     * @param recipient
     * @param company
     * @param reportid
     * @param diameter
     * @param depth
     * @param req
     * @return
     */
    @RequestMapping(value = "/updateYZLDetailInfo")
    @ResponseBody
    public ApiResult updateYZLDetailInfo(String id, String notice_id, String section, String strength, String time,
                                         String writer, String recipient, String company, String reportid, String diameter, String depth
            , HttpServletRequest req) {
        long beamId = super.getBeamId(req);
        Long userId = super.getUserId(req);
        Date time2 = null;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        try {
            time2 = formatter.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if(!noticeService.decideCanAdd(CommonUtils.parseLong(notice_id, 0L), ProcessEnum.YZL.getType())){
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), "未到当前通知单进度");
        }
        YzlNotice yzlNotice = new YzlNotice();
        if (StringUtils.isNotBlank(id))
            yzlNotice.setId(Long.parseLong(id));
        yzlNotice.setNotice_id(Long.parseLong(notice_id));
        yzlNotice.setSection(section);
        yzlNotice.setStrength(strength);
        yzlNotice.setTime(time2);
        yzlNotice.setWriter(writer);
        yzlNotice.setRecipient(recipient);
        yzlNotice.setCompany(company);
        yzlNotice.setBeam_id(beamId);
        yzlNotice.setReportid(reportid);
        yzlNotice.setDiameter(diameter);
        yzlNotice.setDepth(depth);
        ApiResult apiResult = new ApiResult();
        if (StringUtils.isNotBlank(id)) {
            yzlNotice.setUpdater(userId);
            yzlNotice.setUpdatetime(new Date());
            noticeService.updateYzlNotice(yzlNotice);
        } else {
            yzlNotice.setOperator(userId);
            yzlNotice.setAddtime(new Date());
            noticeService.addYzlNotice(yzlNotice);

            ProcNoticeWithDetailVo beamNoByNoticeId = noticeService.getBeamNoByNoticeId(yzlNotice.getNotice_id());
            Message message = new Message();
            message.setType(MessageEnum.PROC_Beam_YZL.getType());
            message.setBeam_id(beamId);
            message.setTitle("预张拉通知单完成新建提醒");
            message.setContent("施工部位：" + beamNoByNoticeId.getBeam_no() + "的预张拉通知单完成新建");
            message.setOperator(userId);
            message.setCode("");
            message.setDetail_url("./process/notice/yzl_notice_detail?notice_id="+beamNoByNoticeId.getNotice_id()+"&step="+(beamNoByNoticeId.getLaststep()+1)
                    +"&cStep="+beamNoByNoticeId.getLaststep()+"&type=1"
            );
            messageService.generateMessageByName(message,yzlNotice.getRecipient());
        }
        return apiResult;
    }


    /**
     *查询預張拉通知单
     * @param id
     * @return
     */
    @RequestMapping(value = "/getYZLDetailInfo")
    @ResponseBody
    public ApiResult getYZLDetailInfo(long id,HttpServletRequest req) {
        ApiResult apiResult = new ApiResult();
        Long beamId = super.getBeamId(req);
        YzlNotice yzlNoticeDetail = noticeService.getYzlNoticeDetail(id,beamId);
        Map<String, Object> map = new HashMap<>();
        map.put("YzlNoticeDetail", yzlNoticeDetail);
        apiResult.setResult(map);
        return apiResult;
    }

    /**
     * 添加更新初张拉通知单
     * @param czlNoticeJson
     * @param request
     * @return
     */
    @RequestMapping(value = "/updateCzlNotice")
    @ResponseBody
    public ApiResult updateCzlNotice(String czlNoticeJson, HttpServletRequest request) {
        if (StringUtils.isEmpty(czlNoticeJson)) {
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        int result = 0;
        try {
            CzlNotice czlNotice = JSON.parseObject(czlNoticeJson, CzlNotice.class);
            if(!noticeService.decideCanAdd(czlNotice.getNotice_id(), ProcessEnum.CZL.getType())){
                return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), "未到当前通知单进度");
            }
            Long beamId = super.getBeamId(request);
            Long userId = super.getUserId(request);
            czlNotice.setBeam_id(beamId);
            czlNotice.setUpdater(userId);
            if (czlNotice.getId() == null)
                czlNotice.setOperator(userId);
            result = noticeService.saveCzlNotice(czlNotice);

        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 1) {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), HttpResultEnum.SUCCESS.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }

    /**
     * 根据noticeid查询初张拉通知单
     *
     * @param notice_id
     * @return
     */
    @RequestMapping(value = "/getCZLDetailInfo")
    @ResponseBody
    public ApiResult getCzlDetailInfo(long notice_id,HttpServletRequest req) {
        ApiResult apiResult = new ApiResult();
        Long beamId = super.getBeamId(req);
        CzlNotice czlNoticeDetail = noticeService.getCzlNotice(notice_id,beamId);
        Map<String, Object> map = new HashMap<>();
        map.put("CzlNoticeDetail", czlNoticeDetail);
        apiResult.setResult(map);
        return apiResult;
    }

    /**
     * 终张拉
     * @param zzlNoticeJson
     * @param request
     * @return
     */
    @RequestMapping(value = "/updateZzlNotice")
    @ResponseBody
    public ApiResult updateZzlNotice(String zzlNoticeJson, HttpServletRequest request) {
        if (StringUtils.isEmpty(zzlNoticeJson)) {
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        int result;
        try {
            ZzlNotice zzlNotice = JSON.parseObject(zzlNoticeJson, ZzlNotice.class);
            if(!noticeService.decideCanAdd(zzlNotice.getNotice_id(), ProcessEnum.ZZL.getType())){
                return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), "未到当前通知单进度");
            }
            Long beamId = super.getBeamId(request);
            Long userId = super.getUserId(request);
            zzlNotice.setBeam_id(beamId);
            zzlNotice.setUpdater(userId);
            if (zzlNotice.getId() == null)
                zzlNotice.setOperator(userId);
            result = noticeService.saveZzlNotice(zzlNotice);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 1) {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), HttpResultEnum.SUCCESS.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }

    /**
     * 查询终张拉
     * @param notice_id
     * @return
     */
    @RequestMapping(value = "/getZzlDetailInfo")
    @ResponseBody
    public ApiResult getZzlDetailInfo(long notice_id,HttpServletRequest request) {
        ApiResult apiResult = new ApiResult();
        Long beamId = super.getBeamId(request);
        ZzlNotice zzlNoticeDetail = noticeService.getZzlNotice(notice_id,beamId);
        Map<String, Object> map = new HashMap<>();
        map.put("ZzlNoticeDetail", zzlNoticeDetail);
        apiResult.setResult(map);
        return apiResult;
    }

    /**
     * 更新移存梁通知
     * @param yclNoticeJson
     * @param request
     * @return
     */
    @RequestMapping(value = "/updateYclNotice")
    @ResponseBody
    public ApiResult updateYclNotice(String yclNoticeJson, HttpServletRequest request) {
        if (StringUtils.isEmpty(yclNoticeJson)) {
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        int result;
        try {
            YclNotice yclNotice = JSON.parseObject(yclNoticeJson, YclNotice.class);
            if(!noticeService.decideCanAdd(yclNotice.getNotice_id(), ProcessEnum.YCL.getType())){
                return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), "未到当前通知单进度");
            }
            Long beamId = super.getBeamId(request);
            Long userId = super.getUserId(request);
            yclNotice.setBeam_id(beamId);
            yclNotice.setUpdater(userId);
            if (yclNotice.getId() == null)
                yclNotice.setOperator(userId);
            result = noticeService.saveYclNotice(yclNotice);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 1) {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), HttpResultEnum.SUCCESS.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }

    /**
     * 查询移存梁通知
     * @param notice_id
     * @return
     */
    @RequestMapping(value = "/getYclDetailInfo")
    @ResponseBody
    public ApiResult getYclDetailInfo(long notice_id,HttpServletRequest req) {
        ApiResult apiResult = new ApiResult();
        Long beamId = super.getBeamId(req);
        YclNotice yclNoticeDetail = noticeService.getYclNotice(notice_id,beamId);
        Map<String, Object> map = new HashMap<>();
        map.put("YclNoticeDetail", yclNoticeDetail);
        apiResult.setResult(map);
        return apiResult;
    }

    /**
     * 切丝、注浆通知单
     */
    @RequestMapping(value = "/updateQszjNotice")
    @ResponseBody
    public ApiResult updateQszjNotice(String qszjNoticeJson, HttpServletRequest request) {
        if (StringUtils.isEmpty(qszjNoticeJson)) {
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        int result;
        try {
            QszjNotice qszjNotice = JSON.parseObject(qszjNoticeJson, QszjNotice.class);
            if(!noticeService.decideCanAdd(qszjNotice.getNotice_id(), ProcessEnum.QSYJ.getType())){
                return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), "未到当前通知单进度");
            }
            Long beamId = super.getBeamId(request);
            Long userId = super.getUserId(request);
            qszjNotice.setBeam_id(beamId);
            qszjNotice.setUpdater(userId);
            if (qszjNotice.getId() == null)
                qszjNotice.setOperator(userId);
            result = noticeService.saveQszjNotice(qszjNotice);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 1) {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), HttpResultEnum.SUCCESS.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }

    @RequestMapping(value = "/getQszjDetailInfo")
    @ResponseBody
    public ApiResult getQszjDetailInfo(long notice_id,HttpServletRequest req) {
        ApiResult apiResult = new ApiResult();
        Long beamId = super.getBeamId(req);
        QszjNotice qszjNoticeDetail = noticeService.getQszjNotice(notice_id,beamId);
        Map<String, Object> map = new HashMap<>();
        map.put("QszjNoticeDetail", qszjNoticeDetail);
        apiResult.setResult(map);
        return apiResult;
    }

    /**
     * 封锚
     */
    @RequestMapping(value = "/updateFmNotice")
    @ResponseBody
    public ApiResult updateFmNotice(String fmNoticeJson, HttpServletRequest request) {
        if (StringUtils.isEmpty(fmNoticeJson)) {
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        int result;
        try {
            FmNotice fmNotice = JSON.parseObject(fmNoticeJson, FmNotice.class);
            if(!noticeService.decideCanAdd(fmNotice.getNotice_id(), ProcessEnum.FM.getType())){
                return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), "未到当前通知单进度");
            }
            Long beamId = super.getBeamId(request);
            Long userId = super.getUserId(request);
            fmNotice.setBeam_id(beamId);
            fmNotice.setUpdater(userId);
            if (fmNotice.getId() == null)
                fmNotice.setOperator(userId);
            result = noticeService.saveFmNotice(fmNotice);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 1) {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), HttpResultEnum.SUCCESS.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }

    @RequestMapping(value = "/getFmDetailInfo")
    @ResponseBody
    public ApiResult getFmDetailInfo(long notice_id,HttpServletRequest req) {
        ApiResult apiResult = new ApiResult();
        Long beamId = super.getBeamId(req);
        FmNotice fmNoticeDetail = noticeService.getFmNotice(notice_id,beamId);
        Map<String, Object> map = new HashMap<>();
        map.put("FmNoticeDetail", fmNoticeDetail);
        apiResult.setResult(map);
        return apiResult;
    }

    /**
     * 更新架梁通知单
     * @param jlNoticeJson
     * @param request
     * @return
     */
    @RequestMapping(value = "/updateJlNotice")
    @ResponseBody
    public ApiResult updateJlNotice(String jlNoticeJson, HttpServletRequest request) {
        if (StringUtils.isEmpty(jlNoticeJson)) {
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        int result;
        try {
            JlNotice jlNotice = JSON.parseObject(jlNoticeJson, JlNotice.class);
            if(!noticeService.decideCanAdd(jlNotice.getNotice_id(), ProcessEnum.JSSG.getType())){
                return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), "未到当前通知单进度");
            }
            Long beamId = super.getBeamId(request);
            Long userId = super.getUserId(request);
            jlNotice.setBeam_id(beamId);
            jlNotice.setUpdater(userId);
            if (jlNotice.getId() == null)
                jlNotice.setOperator(userId);
            result = noticeService.saveJlNotice(jlNotice);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 1) {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), HttpResultEnum.SUCCESS.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }

    /**
     * 查询架梁通知单
     * @param notice_id
     * @return
     */
    @RequestMapping(value = "/getJlDetailInfo")
    @ResponseBody
    public ApiResult getJlDetailInfo(long notice_id,HttpServletRequest req) {
        ApiResult apiResult = new ApiResult();
        Long beamId = super.getBeamId(req);
        JlNotice jlNoticeDetail = noticeService.getJlNotice(notice_id,beamId);
        Map<String, Object> map = new HashMap<>();
        map.put("JlNoticeDetail", jlNoticeDetail);
        apiResult.setResult(map);
        return apiResult;
    }

    /**
     * 更新倒梁通知单
     * @param dlNoticeJson
     * @param request
     * @return
     */
    @RequestMapping(value = "/updateDlNotice")
    @ResponseBody
    public ApiResult updateDlNotice(String dlNoticeJson, HttpServletRequest request) {
        if (StringUtils.isEmpty(dlNoticeJson)) {
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        int result;
        try {
            DlNotice dlNotice = JSON.parseObject(dlNoticeJson, DlNotice.class);
            if(!noticeService.decideCanAdd(dlNotice.getNotice_id(), ProcessEnum.FM.getType())){
                return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), "未到当前通知单进度");
            }
            Long beamId = super.getBeamId(request);
            Long userId = super.getUserId(request);
            dlNotice.setBeam_id(beamId);
            dlNotice.setUpdater(userId);
            if (dlNotice.getId() == null)
                dlNotice.setOperator(userId);
            result = noticeService.saveDlNotice(dlNotice);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 1) {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), HttpResultEnum.SUCCESS.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }

    /**
     * 查询倒梁通知单
     * @param notice_id
     * @return
     */
    @RequestMapping(value = "/getDlDetailInfo")
    @ResponseBody
    public ApiResult getDlDetailInfo(long notice_id,HttpServletRequest req) {
        ApiResult apiResult = new ApiResult();
        Long beamId = super.getBeamId(req);
        DlNotice dlNoticeDetail = noticeService.getDlNotice(notice_id,beamId);
        Map<String, Object> map = new HashMap<>();
        map.put("DlNoticeDetail", dlNoticeDetail);
        apiResult.setResult(map);
        return apiResult;
    }
}
